package WuHanTrainStation;

import java.io.*;
import java.util.*;

//功能类
public class Functional {

    //增加属性
    public void add() throws IOException, ClassNotFoundException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        ArrayList<Train> list = new ArrayList<Train>();
        int judgment = 0;
        Regular regular = new Regular();
        Functional functional = new Functional();
        do {
            try {
                ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("WuHanTrainStationAttribute\\WuHanTrainStation.txt"));
                list = (ArrayList<Train>) objectInputStream.readObject();
                objectInputStream.close();
                System.out.println("请输入你要录入的车次：");
                String trains = bufferedReader.readLine();
                boolean returnTrains = regular.matchingTrains(trains);
                if (returnTrains == false) {
                    System.out.println("您的输入有误，请重新输入");
                    functional.add();
                }
                System.out.println("请输入你要录入的车次到达时间：");
                String arrivingTime = bufferedReader.readLine();
                boolean returnArrivingTime = regular.matchingArrivingTime(arrivingTime);
                if (returnArrivingTime == false) {
                    System.out.println("您的输入有误，请重新输入");
                    functional.add();
                }
                System.out.println("请输入你要录入的车次出发时间：");
                String departureTime = bufferedReader.readLine();
                boolean returnDepartureTime = regular.matchingDepartureTime(departureTime);
                if (returnDepartureTime == false) {
                    System.out.println("您的输入有误，请重新输入");
                    functional.add();
                }
                System.out.println("请输入你要录入的车辆种类：");
                String type = bufferedReader.readLine();
                boolean returnType = regular.matchingType(type);
                if (returnType == false) {
                    System.out.println("您的输入有误，请重新输入");
                    functional.add();
                }
                System.out.println("请输入你要录入的场：");
                String field = bufferedReader.readLine();
                boolean returnField = regular.matchingField(field);
                if (returnField == false) {
                    System.out.println("您的输入有误，请重新输入");
                    functional.add();
                }
                System.out.println("请输入你要录入的车站：");
                String station = bufferedReader.readLine();
                boolean returnStation = regular.matchingStation(station);
                if (returnStation == false) {
                    System.out.println("您的输入有误，请重新输入");
                    functional.add();
                }
                int a = 0;
                Iterator<Train> iterator = list.iterator();
                while (iterator.hasNext()) {
                    Train getTrain = iterator.next();
                    if (trains.equals(getTrain.getTrains()) == false) {
                        System.out.println("可以录入信息");
                        Train train = new Train(trains, arrivingTime, departureTime, type, field, station);
                        list.add(train);
                        ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream("WuHanTrainStationAttribute\\WuHanTrainStation.txt"));
                        objectOutputStream.writeObject(list);
                        System.out.println("录入成功");
                        objectOutputStream.close();
                        judgment = 1;
                        a = 0;
                        break;
                    } else {
                        a = 1;
                    }
                }
                if (a == 1) {
                    System.out.println("录入失败，请重新录入");
                }
            } catch (EOFException e) {
                System.out.println("请输入你要录入的车次：");
                String trains = bufferedReader.readLine();
                boolean returnTrains = regular.matchingTrains(trains);
                if (returnTrains == false) {
                    System.out.println("您的输入有误，请重新输入");
                    functional.add();
                }
                System.out.println("请输入你要录入的车次到达时间：");
                String arrivingTime = bufferedReader.readLine();
                boolean returnArrivingTime = regular.matchingArrivingTime(arrivingTime);
                if (returnArrivingTime == false) {
                    System.out.println("您的输入有误，请重新输入");
                    functional.add();
                }
                System.out.println("请输入你要录入的车次出发时间：");
                String departureTime = bufferedReader.readLine();
                boolean returnDepartureTime = regular.matchingDepartureTime(departureTime);
                if (returnDepartureTime == false) {
                    System.out.println("您的输入有误，请重新输入");
                    functional.add();
                }
                System.out.println("请输入你要录入的车辆种类：");
                String type = bufferedReader.readLine();
                boolean returnType = regular.matchingType(type);
                if (returnType == false) {
                    System.out.println("您的输入有误，请重新输入");
                    functional.add();
                }
                System.out.println("请输入你要录入的场：");
                String field = bufferedReader.readLine();
                boolean returnField = regular.matchingField(field);
                if (returnField == false) {
                    System.out.println("您的输入有误，请重新输入");
                    functional.add();
                }
                System.out.println("请输入你要录入的车站：");
                String station = bufferedReader.readLine();
                boolean returnStation = regular.matchingStation(station);
                if (returnStation == false) {
                    System.out.println("您的输入有误，请重新输入");
                    functional.add();
                }
                Train train = new Train(trains, arrivingTime, departureTime, type, field, station);
                list.add(train);
                ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream("WuHanTrainStationAttribute\\WuHanTrainStation.txt"));
                objectOutputStream.writeObject(list);
                System.out.println("录入成功");
                objectOutputStream.close();
                judgment = 1;
            }
        } while (judgment == 0);
    }

    //按照车次删除
    public void deleteTrains() throws IOException, ClassNotFoundException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        ArrayList<Train> list = new ArrayList<Train>();
        Regular regular = new Regular();
        Functional functional = new Functional();
        ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("WuHanTrainStationAttribute\\WuHanTrainStation.txt"));
        try {
            list = (ArrayList<Train>) objectInputStream.readObject();
            objectInputStream.close();
            System.out.println("请输入你要删除的车次：");
            String deleteTrains = bufferedReader.readLine();
            boolean returnTrains = regular.matchingTrains(deleteTrains);
            if (returnTrains == false) {
                System.out.println("您的输入有误，请重新输入");
                functional.deleteTrains();
            }
            Iterator<Train> iterator = list.iterator();
            int a = 0;
            while (iterator.hasNext()) {
                Train train = iterator.next();
                if (deleteTrains.equals(train.getTrains())) {
                    list.remove(train);
                    System.out.println("该车次信息删除成功");
                    ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream("WuHanTrainStationAttribute\\WuHanTrainStation.txt"));
                    objectOutputStream.writeObject(list);
                    objectOutputStream.close();
                    a = 1;
                    break;
                } else {
                    a = 0;
                }
            }
            if (a != 1) {
                System.out.println("该车次信息删除失败，请核对车辆信息");
            }
        } catch (EOFException e) {
            System.out.println("您还没有录入车次，无法删除，请先录入车次");
        }
    }

    //按照到达时间删除
    public void deleteArrivingTime() throws IOException, ClassNotFoundException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        ArrayList<Train> list = new ArrayList<Train>();
        ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("WuHanTrainStationAttribute\\WuHanTrainStation.txt"));
        Regular regular = new Regular();
        Functional functional = new Functional();
        try {
            list = (ArrayList<Train>) objectInputStream.readObject();
            objectInputStream.close();
            System.out.println("请输入你要删除的到达时间：");
            String deleteArrivingTime = bufferedReader.readLine();
            boolean returnArrivingTime = regular.matchingArrivingTime(deleteArrivingTime);
            if (returnArrivingTime == false) {
                System.out.println("您的输入有误，请重新输入");
                functional.deleteArrivingTime();
            }
            Iterator<Train> iterator = list.iterator();
            int a = 0;
            while (iterator.hasNext()) {
                Train train = iterator.next();
                if (deleteArrivingTime.equals(train.getArrivingTime())) {
                    list.remove(train);
                    System.out.println("该车次信息删除成功");
                    ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream("WuHanTrainStationAttribute\\WuHanTrainStation.txt"));
                    objectOutputStream.writeObject(list);
                    objectOutputStream.close();
                    a = 1;
                    break;
                } else {
                    a = 0;
                }
            }
            if (a != 1) {
                System.out.println("该车次信息删除失败，请核对车辆信息");
            }
        } catch (EOFException e) {
            System.out.println("您还没有录入车次，无法删除，请先录入车次");
        }
    }

    //按照出发时间删除
    public void deleteDepartureTime() throws IOException, ClassNotFoundException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        ArrayList<Train> list = new ArrayList<Train>();
        Regular regular = new Regular();
        Functional functional = new Functional();
        ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("WuHanTrainStationAttribute\\WuHanTrainStation.txt"));
        try {
            list = (ArrayList<Train>) objectInputStream.readObject();
            objectInputStream.close();
            System.out.println("请输入你要删除的出发时间：");
            String deleteDepartureTime = bufferedReader.readLine();
            boolean returnDepartureTime = regular.matchingDepartureTime(deleteDepartureTime);
            if (returnDepartureTime == false) {
                System.out.println("您的输入有误，请重新输入");
                functional.deleteDepartureTime();
            }
            Iterator<Train> iterator = list.iterator();
            int a = 0;
            while (iterator.hasNext()) {
                Train train = iterator.next();
                if (deleteDepartureTime.equals(train.getDepartureTime())) {
                    list.remove(train);
                    System.out.println("该车次信息删除成功");
                    ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream("WuHanTrainStationAttribute\\WuHanTrainStation.txt"));
                    objectOutputStream.writeObject(list);
                    objectOutputStream.close();
                    a = 1;
                    break;
                } else {
                    a = 0;
                }
            }
            if (a != 1) {
                System.out.println("该车次信息删除失败，请核对车辆信息");
            }
        } catch (EOFException e) {
            System.out.println("您还没有录入车次，无法删除，请先录入车次");
        }
    }

    //按照车次类型删除
    public void deleteType() throws IOException, ClassNotFoundException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        ArrayList<Train> list = new ArrayList<Train>();
        Regular regular = new Regular();
        Functional functional = new Functional();
        ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("WuHanTrainStationAttribute\\WuHanTrainStation.txt"));
        try {
            list = (ArrayList<Train>) objectInputStream.readObject();
            objectInputStream.close();
            System.out.println("请输入你要删除的车辆类型：");
            String deleteType = bufferedReader.readLine();
            boolean returnType = regular.matchingType(deleteType);
            if (returnType == false) {
                System.out.println("您的输入有误，请重新输入");
                functional.deleteType();
            }
            Iterator<Train> iterator = list.iterator();
            int a = 0;
            while (iterator.hasNext()) {
                Train train = iterator.next();
                if (deleteType.equals(train.getType())) {
                    list.remove(train);
                    System.out.println("该车次信息删除成功");
                    ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream("WuHanTrainStationAttribute\\WuHanTrainStation.txt"));
                    objectOutputStream.writeObject(list);
                    objectOutputStream.close();
                    a = 1;
                    break;
                } else {
                    a = 0;
                }
            }
            if (a != 1) {
                System.out.println("该车次信息删除失败，请核对车辆信息");
            }
        } catch (EOFException e) {
            System.out.println("您还没有录入车次，无法删除，请先录入车次");
        }
    }

    //按照场删除
    public void deleteField() throws IOException, ClassNotFoundException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        ArrayList<Train> list = new ArrayList<Train>();
        Regular regular = new Regular();
        Functional functional = new Functional();
        ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("WuHanTrainStationAttribute\\WuHanTrainStation.txt"));
        try {
            list = (ArrayList<Train>) objectInputStream.readObject();
            objectInputStream.close();
            System.out.println("请输入你要删除的场：");
            String deleteField = bufferedReader.readLine();
            boolean returnField = regular.matchingField(deleteField);
            if (returnField == false) {
                System.out.println("您的输入有误，请重新输入");
                functional.deleteField();
            }
            Iterator<Train> iterator = list.iterator();
            int a = 0;
            while (iterator.hasNext()) {
                Train train = iterator.next();
                if (deleteField.equals(train.getField())) {
                    list.remove(train);
                    System.out.println("该车次信息删除成功");
                    ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream("WuHanTrainStationAttribute\\WuHanTrainStation.txt"));
                    objectOutputStream.writeObject(list);
                    objectOutputStream.close();
                    a = 1;
                    break;
                } else {
                    a = 0;
                }
            }
            if (a != 1) {
                System.out.println("该车次信息删除失败，请核对车辆信息");
            }
        } catch (EOFException e) {
            System.out.println("您还没有录入车次，无法删除，请先录入车次");
        }
    }

    //按照车站删除
    public void deleteStation() throws IOException, ClassNotFoundException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        ArrayList<Train> list = new ArrayList<Train>();
        Regular regular = new Regular();
        Functional functional = new Functional();
        ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("WuHanTrainStationAttribute\\WuHanTrainStation.txt"));
        try {
            list = (ArrayList<Train>) objectInputStream.readObject();
            objectInputStream.close();
            System.out.println("请输入你要删除的车站：");
            String deleteStation = bufferedReader.readLine();
            boolean returnStation = regular.matchingField(deleteStation);
            if (returnStation == false) {
                System.out.println("您的输入有误，请重新输入");
                functional.deleteStation();
            }
            Iterator<Train> iterator = list.iterator();
            int a = 0;
            while (iterator.hasNext()) {
                Train train = iterator.next();
                if (deleteStation.equals(train.getStation())) {
                    list.remove(train);
                    System.out.println("该车次信息删除成功");
                    ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream("WuHanTrainStationAttribute\\WuHanTrainStation.txt"));
                    objectOutputStream.writeObject(list);
                    objectOutputStream.close();
                    a = 1;
                    break;
                } else {
                    a = 0;
                }
            }
            if (a != 1) {
                System.out.println("该车次信息删除失败，请核对车辆信息");
            }
        } catch (EOFException e) {
            System.out.println("您还没有录入车次，无法删除，请先录入车次");
        }
    }

    //更改车次
    public void changeTrains() throws IOException, ClassNotFoundException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        ArrayList<Train> list = new ArrayList<Train>();
        Regular regular = new Regular();
        Functional functional = new Functional();
        ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("WuHanTrainStationAttribute\\WuHanTrainStation.txt"));
        try {
            list = (ArrayList<Train>) objectInputStream.readObject();
            objectInputStream.close();
            System.out.println("请输入你要修改的车次：");
            String readTrains = bufferedReader.readLine();
            boolean returnTrains = regular.matchingTrains(readTrains);
            if (returnTrains == false) {
                System.out.println("您的输入有误，请重新输入");
                functional.changeTrains();
            }
            Iterator<Train> iterator = list.iterator();
            int a = 0;
            while (iterator.hasNext()) {
                Train train = iterator.next();
                if (readTrains.equals(train.getTrains())) {
                    String getArrivingTime = train.getArrivingTime();
                    String getDepartureTime = train.getDepartureTime();
                    String getType = train.getType();
                    String getField = train.getField();
                    String getStation = train.getStation();
                    list.remove(train);
                    System.out.println("请输入修改后的车次：");
                    String changeTrains = bufferedReader.readLine();
                    boolean returnNewTrains = regular.matchingTrains(changeTrains);
                    if (returnNewTrains == false) {
                        System.out.println("您的输入有误，请重新输入");
                        functional.changeTrains();
                    }
                    if (!changeTrains.equals(train.getTrains())) {
                        Train newTrain = new Train(changeTrains, getArrivingTime, getDepartureTime, getType, getField, getStation);
                        list.add(newTrain);
                        ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream("WuHanTrainStationAttribute\\WuHanTrainStation.txt"));
                        objectOutputStream.writeObject(list);
                        System.out.println("修改成功");
                        objectOutputStream.close();
                        a = 1;
                        break;
                    }
                } else {
                    a = 0;
                }
            }
            if (a != 1) {
                System.out.println("该车次信息更改失败，请核对车辆信息");
            }
        } catch (EOFException e) {
            System.out.println("您还没有录入车次，无法更改，请先录入车次");
        }
    }

    //更改到达时间
    public void changeArrivingTime() throws IOException, ClassNotFoundException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        ArrayList<Train> list = new ArrayList<Train>();
        Regular regular = new Regular();
        Functional functional = new Functional();
        ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("WuHanTrainStationAttribute\\WuHanTrainStation.txt"));
        try {
            list = (ArrayList<Train>) objectInputStream.readObject();
            objectInputStream.close();
            System.out.println("请输入你要修改的到达时间：");
            String readArrivingTime = bufferedReader.readLine();
            boolean returnArrivingTime = regular.matchingArrivingTime(readArrivingTime);
            if (returnArrivingTime == false) {
                System.out.println("您的输入有误，请重新输入");
                functional.changeArrivingTime();
            }
            Iterator<Train> iterator = list.iterator();
            int a = 0;
            while (iterator.hasNext()) {
                Train train = iterator.next();
                if (readArrivingTime.equals(train.getArrivingTime())) {
                    String getTrains = train.getTrains();
                    String getDepartureTime = train.getDepartureTime();
                    String getType = train.getType();
                    String getField = train.getField();
                    String getStation = train.getStation();
                    list.remove(train);
                    System.out.println("请输入修改后的到达时间：");
                    String changeArrivingTime = bufferedReader.readLine();
                    boolean returnNewArrivingTime = regular.matchingArrivingTime(changeArrivingTime);
                    if (returnNewArrivingTime == false) {
                        System.out.println("您的输入有误，请重新输入");
                        functional.changeArrivingTime();
                    }
                    if (!changeArrivingTime.equals(train.getArrivingTime())) {
                        Train newTrain = new Train(getTrains, changeArrivingTime, getDepartureTime, getType, getField, getStation);
                        list.add(newTrain);
                        ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream("WuHanTrainStationAttribute\\WuHanTrainStation.txt"));
                        objectOutputStream.writeObject(list);
                        System.out.println("修改成功");
                        objectOutputStream.close();
                        a = 1;
                        break;
                    }
                } else {
                    a = 0;
                }
            }
            if (a != 1) {
                System.out.println("该车次信息更改失败，请核对车辆信息");
            }
        } catch (EOFException e) {
            System.out.println("您还没有录入车次，无法更改，请先录入车次");
        }
    }

    //更改出发时间
    public void changeDepartureTime() throws IOException, ClassNotFoundException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        ArrayList<Train> list = new ArrayList<Train>();
        Regular regular = new Regular();
        Functional functional = new Functional();
        ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("WuHanTrainStationAttribute\\WuHanTrainStation.txt"));
        try {
            list = (ArrayList<Train>) objectInputStream.readObject();
            objectInputStream.close();
            System.out.println("请输入你要修改的出发时间：");
            String readDepartureTime = bufferedReader.readLine();
            boolean returnDepartureTime = regular.matchingDepartureTime(readDepartureTime);
            if (returnDepartureTime == false) {
                System.out.println("您的输入有误，请重新输入");
                functional.deleteDepartureTime();
            }
            Iterator<Train> iterator = list.iterator();
            int a = 0;
            while (iterator.hasNext()) {
                Train train = iterator.next();
                if (readDepartureTime.equals(train.getDepartureTime())) {
                    String getTrains = train.getTrains();
                    String getArrivingTime = train.getArrivingTime();
                    String getType = train.getType();
                    String getField = train.getField();
                    String getStation = train.getStation();
                    list.remove(train);
                    System.out.println("请输入修改后的出发时间：");
                    String changeDepartureTime = bufferedReader.readLine();
                    boolean returnNewDepartureTime = regular.matchingDepartureTime(changeDepartureTime);
                    if (returnNewDepartureTime == false) {
                        System.out.println("您的输入有误，请重新输入");
                        functional.deleteDepartureTime();
                    }
                    if (!changeDepartureTime.equals(train.getDepartureTime())) {
                        Train newTrain = new Train(getTrains, getArrivingTime, changeDepartureTime, getType, getField, getStation);
                        list.add(newTrain);
                        ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream("WuHanTrainStationAttribute\\WuHanTrainStation.txt"));
                        objectOutputStream.writeObject(list);
                        System.out.println("修改成功");
                        objectOutputStream.close();
                        a = 1;
                        break;
                    }
                } else {
                    a = 0;
                }
            }
            if (a != 1) {
                System.out.println("该车次信息更改失败，请核对车辆信息");
            }
        } catch (EOFException e) {
            System.out.println("您还没有录入车次，无法更改，请先录入车次");
        }
    }

    //更改车辆类型
    public void changeType() throws IOException, ClassNotFoundException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        ArrayList<Train> list = new ArrayList<Train>();
        Regular regular = new Regular();
        Functional functional = new Functional();
        ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("WuHanTrainStationAttribute\\WuHanTrainStation.txt"));
        try {
            list = (ArrayList<Train>) objectInputStream.readObject();
            objectInputStream.close();
            System.out.println("请输入你要修改的车辆类型：");
            String readType = bufferedReader.readLine();
            boolean returnType = regular.matchingType(readType);
            if (returnType == false) {
                System.out.println("您的输入有误，请重新输入");
                functional.changeType();
            }
            Iterator<Train> iterator = list.iterator();
            int a = 0;
            while (iterator.hasNext()) {
                Train train = iterator.next();
                if (readType.equals(train.getType())) {
                    String getTrains = train.getTrains();
                    String getArrivingTime = train.getArrivingTime();
                    String getDepartureTime = train.getDepartureTime();
                    String getField = train.getField();
                    String getStation = train.getStation();
                    list.remove(train);
                    System.out.println("请输入修改后的车辆类型：");
                    String changeType = bufferedReader.readLine();
                    boolean returnNewType = regular.matchingType(changeType);
                    if (returnNewType == false) {
                        System.out.println("您的输入有误，请重新输入");
                        functional.changeType();
                    }
                    if (!changeType.equals(train.getType())) {
                        Train newTrain = new Train(getTrains, getArrivingTime, getDepartureTime, changeType, getField, getStation);
                        list.add(newTrain);
                        ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream("WuHanTrainStationAttribute\\WuHanTrainStation.txt"));
                        objectOutputStream.writeObject(list);
                        System.out.println("修改成功");
                        objectOutputStream.close();
                        a = 1;
                        break;
                    }
                } else {
                    a = 0;
                }
            }
            if (a != 1) {
                System.out.println("该车次信息更改失败，请核对车辆信息");
            }
        } catch (EOFException e) {
            System.out.println("您还没有录入车次，无法更改，请先录入车次");
        }
    }

    //更改场
    public void changeField() throws IOException, ClassNotFoundException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        ArrayList<Train> list = new ArrayList<Train>();
        Regular regular = new Regular();
        Functional functional = new Functional();
        ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("WuHanTrainStationAttribute\\WuHanTrainStation.txt"));
        try {
            list = (ArrayList<Train>) objectInputStream.readObject();
            objectInputStream.close();
            System.out.println("请输入你要修改的场：");
            String readField = bufferedReader.readLine();
            boolean returnField = regular.matchingField(readField);
            if (returnField == false) {
                System.out.println("您的输入有误，请重新输入");
                functional.changeField();
            }
            Iterator<Train> iterator = list.iterator();
            int a = 0;
            while (iterator.hasNext()) {
                Train train = iterator.next();
                if (readField.equals(train.getField())) {
                    String getTrains = train.getTrains();
                    String getArrivingTime = train.getArrivingTime();
                    String getDepartureTime = train.getDepartureTime();
                    String getType = train.getType();
                    String getStation = train.getStation();
                    list.remove(train);
                    System.out.println("请输入修改后的场：");
                    String changeField = bufferedReader.readLine();
                    boolean returnNewField = regular.matchingField(changeField);
                    if (returnNewField == false) {
                        System.out.println("您的输入有误，请重新输入");
                        functional.changeField();
                    }
                    if (!changeField.equals(train.getField())) {
                        Train newTrain = new Train(getTrains, getArrivingTime, getDepartureTime, getType, changeField, getStation);
                        list.add(newTrain);
                        ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream("WuHanTrainStationAttribute\\WuHanTrainStation.txt"));
                        objectOutputStream.writeObject(list);
                        System.out.println("修改成功");
                        objectOutputStream.close();
                        a = 1;
                        break;
                    }
                } else {
                    a = 0;
                }
            }
            if (a != 1) {
                System.out.println("该车次信息更改失败，请核对车辆信息");
            }
        } catch (EOFException e) {
            System.out.println("您还没有录入车次，无法更改，请先录入车次");
        }
    }

    //更改车站
    public void changeStation() throws IOException, ClassNotFoundException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        ArrayList<Train> list = new ArrayList<Train>();
        Regular regular = new Regular();
        Functional functional = new Functional();
        ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("WuHanTrainStationAttribute\\WuHanTrainStation.txt"));
        try {
            list = (ArrayList<Train>) objectInputStream.readObject();
            objectInputStream.close();
            System.out.println("请输入你要修改的车站：");
            String readStation = bufferedReader.readLine();
            boolean returnStation = regular.matchingField(readStation);
            if (returnStation == false) {
                System.out.println("您的输入有误，请重新输入");
                functional.changeStation();
            }
            Iterator<Train> iterator = list.iterator();
            int a = 0;
            while (iterator.hasNext()) {
                Train train = iterator.next();
                if (readStation.equals(train.getStation())) {
                    String getArrivingTime = train.getArrivingTime();
                    String getDepartureTime = train.getDepartureTime();
                    String getType = train.getType();
                    String getField = train.getField();
                    String getTrain = train.getTrains();
                    list.remove(train);
                    System.out.println("请输入修改后的车站：");
                    String changeStation = bufferedReader.readLine();
                    boolean returnNewStation = regular.matchingField(readStation);
                    if (returnNewStation == false) {
                        System.out.println("您的输入有误，请重新输入");
                        functional.changeStation();
                    }
                    if (!changeStation.equals(train.getStation())) {
                        Train newTrain = new Train(getTrain, getArrivingTime, getDepartureTime, getType, getField, changeStation);
                        list.add(newTrain);
                        ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream("WuHanTrainStationAttribute\\WuHanTrainStation.txt"));
                        objectOutputStream.writeObject(list);
                        System.out.println("修改成功");
                        objectOutputStream.close();
                        a = 1;
                        break;
                    }
                } else {
                    a = 0;
                }
            }
            if (a != 1) {
                System.out.println("该车次信息更改失败，请核对车辆信息");
            }
        } catch (EOFException e) {
            System.out.println("您还没有录入车次，无法更改，请先录入车次");
        }
    }

    //查询车次
    public void queryTrains() throws IOException, ClassNotFoundException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        ArrayList<Train> list = new ArrayList<Train>();
        Regular regular = new Regular();
        Functional functional = new Functional();
        ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("WuHanTrainStationAttribute\\WuHanTrainStation.txt"));
        try {
            list = (ArrayList<Train>) objectInputStream.readObject();
            objectInputStream.close();
            System.out.println("请输入你要查询的车次：");
            String queryTrains = bufferedReader.readLine();
            boolean returnTrains = regular.matchingTrains(queryTrains);
            if (returnTrains == false) {
                System.out.println("您的输入有误，请重新输入");
                functional.changeTrains();
            }
            Iterator<Train> iterator = list.iterator();
            int a = 0;
            while (iterator.hasNext()) {
                Train train = iterator.next();
                if (queryTrains.equals(train.getTrains())) {
                    System.out.println(train.toString());
                    System.out.println("查询成功");
                    a = 1;
                    break;
                } else {
                    a = 0;
                }
            }
            if (a != 1) {
                System.out.println("无该车次信息，查询失败");
            }
        } catch (EOFException e) {
            System.out.println("您还没有录入车次，无法查询，请先录入车次");
        }
    }

    //查询到达时间
    public void queryArrivingTime() throws IOException, ClassNotFoundException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        ArrayList<Train> list = new ArrayList<Train>();
        Regular regular = new Regular();
        Functional functional = new Functional();
        ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("WuHanTrainStationAttribute\\WuHanTrainStation.txt"));
        try {
            list = (ArrayList<Train>) objectInputStream.readObject();
            objectInputStream.close();
            System.out.println("请输入你要查询的到达时间：");
            String queryArrivingTime = bufferedReader.readLine();
            boolean returnArrivingTime = regular.matchingArrivingTime(queryArrivingTime);
            if (returnArrivingTime == false) {
                System.out.println("您的输入有误，请重新输入");
                functional.changeArrivingTime();
            }
            Iterator<Train> iterator = list.iterator();
            int a = 0;
            while (iterator.hasNext()) {
                Train train = iterator.next();
                if (queryArrivingTime.equals(train.getArrivingTime())) {
                    System.out.println(train.toString());
                    System.out.println("查询成功");
                    a = 1;
                    break;
                } else {
                    a = 0;
                }
            }
            if (a != 1) {
                System.out.println("无该车次信息，查询失败");
            }
        } catch (EOFException e) {
            System.out.println("您还没有录入车次，无法查询，请先录入车次");
        }
    }

    //查询出发时间
    public void queryDepartureTime() throws IOException, ClassNotFoundException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        ArrayList<Train> list = new ArrayList<Train>();
        Regular regular = new Regular();
        Functional functional = new Functional();
        ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("WuHanTrainStationAttribute\\WuHanTrainStation.txt"));
        try {
            list = (ArrayList<Train>) objectInputStream.readObject();
            objectInputStream.close();
            System.out.println("请输入你要查询的出发时间：");
            String queryDepartureTime = bufferedReader.readLine();
            boolean returnDepartureTime = regular.matchingDepartureTime(queryDepartureTime);
            if (returnDepartureTime == false) {
                System.out.println("您的输入有误，请重新输入");
                functional.deleteDepartureTime();
            }
            Iterator<Train> iterator = list.iterator();
            int a = 0;
            while (iterator.hasNext()) {
                Train train = iterator.next();
                if (queryDepartureTime.equals(train.getDepartureTime())) {
                    System.out.println(train.toString());
                    System.out.println("查询成功");
                    a = 1;
                    break;
                } else {
                    a = 0;
                }
            }
            if (a != 1) {
                System.out.println("无该车次信息，查询失败");
            }
        } catch (EOFException e) {
            System.out.println("您还没有录入车次，无法查询，请先录入车次");
        }
    }

    //查询车辆类型
    public void queryType() throws IOException, ClassNotFoundException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        ArrayList<Train> list = new ArrayList<Train>();
        Regular regular = new Regular();
        Functional functional = new Functional();
        ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("WuHanTrainStationAttribute\\WuHanTrainStation.txt"));
        try {
            list = (ArrayList<Train>) objectInputStream.readObject();
            objectInputStream.close();
            System.out.println("请输入你要查询的车次类型：");
            String queryType = bufferedReader.readLine();
            boolean returnType = regular.matchingType(queryType);
            if (returnType == false) {
                System.out.println("您的输入有误，请重新输入");
                functional.queryType();
            }
            Iterator<Train> iterator = list.iterator();
            int a = 0;
            while (iterator.hasNext()) {
                Train train = iterator.next();
                if (queryType.equals(train.getType())) {
                    System.out.println(train.toString());
                    System.out.println("查询成功");
                    a = 1;
                    break;
                } else {
                    a = 0;
                }
            }
            if (a != 1) {
                System.out.println("无该车次信息，查询失败");
            }
        } catch (EOFException e) {
            System.out.println("您还没有录入车次，无法查询，请先录入车次");
        }
    }

    //查询场
    public void queryField() throws IOException, ClassNotFoundException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        ArrayList<Train> list = new ArrayList<Train>();
        Regular regular = new Regular();
        Functional functional = new Functional();
        ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("WuHanTrainStationAttribute\\WuHanTrainStation.txt"));
        try {
            list = (ArrayList<Train>) objectInputStream.readObject();
            objectInputStream.close();
            System.out.println("请输入你要查询的场：");
            String queryField = bufferedReader.readLine();
            boolean returnField = regular.matchingField(queryField);
            if (returnField == false) {
                System.out.println("您的输入有误，请重新输入");
                functional.queryField();
            }
            Iterator<Train> iterator = list.iterator();
            int a = 0;
            while (iterator.hasNext()) {
                Train train = iterator.next();
                if (queryField.equals(train.getField())) {
                    System.out.println(train.toString());
                    System.out.println("查询成功");
                    a = 1;
                    break;
                } else {
                    a = 0;
                }
            }
            if (a != 1) {
                System.out.println("无该车次信息，查询失败");
            }
        } catch (EOFException e) {
            System.out.println("您还没有录入车次，无法查询，请先录入车次");
        }
    }

    //查询车站
    public void queryStation() throws IOException, ClassNotFoundException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        ArrayList<Train> list = new ArrayList<Train>();
        Regular regular = new Regular();
        Functional functional = new Functional();
        ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("WuHanTrainStationAttribute\\WuHanTrainStation.txt"));
        try {
            list = (ArrayList<Train>) objectInputStream.readObject();
            objectInputStream.close();
            System.out.println("请输入你要查询的车站：");
            String queryStation = bufferedReader.readLine();
            boolean returnStation = regular.matchingField(queryStation);
            if (returnStation == false) {
                System.out.println("您的输入有误，请重新输入");
                functional.queryStation();
            }
            Iterator<Train> iterator = list.iterator();
            int a = 0;
            while (iterator.hasNext()) {
                Train train = iterator.next();
                if (queryStation.equals(train.getStation())) {
                    System.out.println(train.toString());
                    System.out.println("查询成功");
                    a = 1;
                    break;
                } else {
                    a = 0;
                }
            }
            if (a != 1) {
                System.out.println("无该车次信息，查询失败");
            }
        } catch (EOFException e) {
            System.out.println("您还没有录入车次，无法查询，请先录入车次");
        }
    }
}